<?php

function reequipment_adminapi_createcompanyschedule($args)
{
    extract($args);

    // Argument check - make sure that all required arguments are present,
    // if not then set an appropriate error message and return
    $invalid = array();
   	if (!isset($company_id) || !is_int($company_id)) {
        $invalid[] = 'company_id';
    } 
   	if (!isset($schedule_id) || !is_int($schedule_id)) {
        $invalid[] = 'schedule_id';
    }
   	if (!isset($equipment_id) || !is_int($equipment_id)) {
        $invalid[] = 'equipment_id';
    }    
    if (count($invalid) > 0) {
        $msg = xarML('Invalid #(1)', join(', ', $invalid));
        xarErrorSet(XAR_SYSTEM_EXCEPTION, 'BAD_PARAM', new SystemException($msg));
        return;
    } 
    
	// Handle the times.  When adding, date scheduled is here, but date completed should not be.
    $last_scheduled = time();
	
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $table = $xartable['recompanyschedule'];

    $query = "INSERT INTO $table ("
        . " schedule_id, company_id, equipment_id, last_scheduled )"
        . " VALUES (?, ?, ?)";
    $result =& $dbconn->Execute($query, array($schedule_id, $company_id, $equipment_id, $last_scheduled));
    if (!$result) return;
    return true;
}
?>